﻿using System;
using System.Configuration;
using System.Data;
using Wxits.Data;
using Wxits.Helper;

public partial class Admin_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Title = ConfigurationManager.AppSettings["systemName"];
            string appid =  ConfigurationManager.AppSettings["appID"];
            top.Attributes.Add("style", "width:1024px; height:120px; background-image:url('../App_Themes/Flat/Login/" + appid + "-top.jpg')");

        }
    }

    /// <summary>
    /// 用户登录
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string UserName = txtAccount.Text.Trim();
        string Password = txtPwd.Text.Trim();
        if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password))
        {
            Common.Show(this, "用户名、密码不能为空");

        }

        if (DataCheck.CheckLogin(UserName, Password))
        {
            string strSQL = @"SELECT * FROM Sys_Users WHERE adminUid = '{0}' ";
            DataTable dt = DBAccess.ExecuteDataTable(string.Format(strSQL, HelpCookie.GetDecrypt("AdminUid")));
            if (dt.Rows.Count == 0)
            {
                Common.ShowAndGoback(this, "用户名不存在");
                return;
            }


            if (dt.Rows[0]["Status"].ToString() != "1")
            {
                Common.Show(this, "您的账号已冻结，请与管理员联系");
                DataCheck.Logout();
                txtPwd.Text = string.Empty;
                return;
            }

            if (UserName.ToLower() != "admin")
            {
                TableEntity entity = new TableEntity("Mall_Logs");
                entity.Add("UserName", UserName);
                entity.Add("UserType", 2);
                entity.Add("LogsType", 1);
                entity.Add("Ip", Common.GetClientIp());
                entity.Add("UserAgent", Request.ServerVariables["HTTP_USER_AGENT"]);
                entity.Add("Description", "管理员【" + UserName + "】登录");
                entity.ExecuteNonQueryBySQL();
            }


            Response.Redirect("Default.aspx");
        }
        else
        {
            Common.Show(this, "用户名或密码错误，请重新登录");
            txtAccount.Text = string.Empty;
            txtPwd.Text = string.Empty;
        }
    }


}
